package com.dhcc.bpm.modules.log.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dhcc.bpm.common.annotation.Log;
import com.dhcc.bpm.common.enums.BusinessType;
import com.dhcc.bpm.modules.log.entity.Logininfor;
import com.dhcc.bpm.modules.log.service.ILogininforService;
import com.dhcc.bpm.modules.log.vo.LogininforVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.Map;

/**
 * @ClassName LogininforController.class
 * @Description  系统访问记录 控制器
 * @Author xiaFaYu
 * @Date 2020-02-03 14:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("bpm-log/logininfor")
@Api(value = "系统访问记录", tags = "系统访问记录接口")
public class LogininforController extends BladeController {
	private  final static Logger log = LoggerFactory.getLogger(LogininforController.class);
	private ILogininforService logininforService;

	/**
	 * @Description 详情
	 * @Author xiafayu
	 * @Date 2020/2/24 15:12
	 * @param logininfor
	 * @return org.springblade.core.tool.api.R<com.dhcc.bpm.modules.log.entity.Logininfor>
	 **/
	@ApiLog("登录详情")
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入logininfor")
	@Log(title = "查询登录详情", businessType = BusinessType.SELECT)
	public R<Logininfor> detail(Logininfor logininfor) {
		Logininfor detail = logininforService.getOne(Condition.getQueryWrapper(logininfor));
		return R.data(detail);
	}

	/**
	 * @Description 分页 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:12
	 * @param logininfor
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.log.entity.Logininfor>>
	 **/
	@ApiLog("登录记录分页查询")
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入logininfor")
	@Log(title = "查询登录记录", businessType = BusinessType.SELECT)
	public R<IPage<Logininfor>> list(@ApiIgnore @RequestParam Map<String, Object> logininfor, Query query) {
		IPage<Logininfor> pages = logininforService.page(Condition.getPage(query), Condition.getQueryWrapper(logininfor, Logininfor.class));
		return R.data(pages);
	}

	/**
	 * @Description 自定义分页 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:12
	 * @param logininfor
	 * @param query
	 * @return org.springblade.core.tool.api.R<com.baomidou.mybatisplus.core.metadata.IPage<com.dhcc.bpm.modules.log.vo.LogininforVO>>
	 **/
	@ApiLog("登录记录分页查询")
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入logininfor")
	@Log(title = "查询登录记录", businessType = BusinessType.SELECT)
	public R<IPage<LogininforVO>> page(LogininforVO logininfor, Query query) {
		if (logininfor.getLoginDate() != null && logininfor.getLoginDate().length() > 0) {
			String startDate = logininfor.getLoginDate().split(",")[0];
			String endDate = logininfor.getLoginDate().split(",")[1];
			logininfor.setStartDate(startDate);
			logininfor.setEndDate(endDate);
		}
		IPage<LogininforVO> pages = logininforService.selectLogininforPage(Condition.getPage(query), logininfor);
		return R.data(pages);
	}

	/**
	 * @Description 新增 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:13
	 * @param logininfor
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("登录记录新增")
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入logininfor")
	@Log(title = "新增登录记录", businessType = BusinessType.INSERT)
	public R save(@Valid @RequestBody Logininfor logininfor) {
		return R.status(logininforService.save(logininfor));
	}

	/**
	 * @Description 修改 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:13
	 * @param logininfor
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("登录记录修改")
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入logininfor")
	@Log(title = "修改登录记录", businessType = BusinessType.UPDATE)
	public R update(@Valid @RequestBody Logininfor logininfor) {
		return R.status(logininforService.updateById(logininfor));
	}

	/**
	 * @Description 新增或修改 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:13
	 * @param logininfor
	 * @return org.springblade.core.tool.api.R
	 **/
	@ApiLog("登录记录新增修改")
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入logininfor")
	@Log(title = "修改登录记录", businessType = BusinessType.UPDATE)
	public R submit(@Valid @RequestBody Logininfor logininfor) {
		return R.status(logininforService.saveOrUpdate(logininfor));
	}

	
	/**
	 * @Description 删除 系统访问记录
	 * @Author xiafayu
	 * @Date 2020/2/24 15:13
	 * @param ids
	 * @return org.springblade.core.tool.api.R
	 **/
	@PostMapping("/remove")
	@ApiLog("登录记录删除")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	@Log(title = "删除登录记录", businessType = BusinessType.DELETE)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(logininforService.deleteLogic(Func.toLongList(ids)));
	}

}
